<script setup>
import { get } from 'lodash';
import { gameList, gameData } from '@/common/data.js';
import {
  getUrlParam,
  getTopLevelDomain,
  formatConfig,
  categoryList,
  getQuery,
  toQuery,
} from '@/common/utils.js';
import { onMounted, onBeforeUnmount, ref, computed, watch, nextTick } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { capitalizeFirstLetter } from '@/common/utils.js';
import GameItem from './GItem.vue';

let cur = {};

const route = useRoute();
const router = useRouter();

// 获取当前选中的分类
const currentCategory = computed(() => {
  if (route.name === 'Games') {
    const pathParts = route.path.split('/');
    const category = pathParts[pathParts.length - 1];
    return capitalizeFirstLetter(category);
  }
  return null;
});

// 分类导航容器引用
const categoryNavContainer = ref(null);

const handleCategoryClick = (category) => {
  const query = getQuery(`/games/${category}`);
  if (route.name === 'Games' && route.path === query.path) {
    window.scrollTo({
      top: 0,
      behavior: 'smooth',
    });
    return;
  }
  router.push(query);
};

// 滚动到当前选中的分类
const scrollToActiveCategory = () => {
  nextTick(() => {
    if (!categoryNavContainer.value) return;
    const activeItem = categoryNavContainer.value.querySelector('.category-nav-item.active');
    if (activeItem) {
      activeItem.scrollIntoView({
        behavior: 'smooth',
        block: 'nearest',
        inline: 'center',
      });
    }
  });
};

// 监听路由变化，自动滚动到当前分类
watch(
  () => route.path,
  () => {
    if (route.name === 'Games') {
      scrollToActiveCategory();
    }
  },
  { immediate: true },
);

const handleLogoClick = () => {
  if (route.name === 'Home') {
    window.scrollTo({
      top: 0,
      behavior: 'smooth',
    });
  } else {
    router.push(getQuery('/'));
  }
};

const handleSearchClick = () => {
  router.push(getQuery('/search'));
};

const handleBannerGameClick = (game) => {
  const { url } = game;
  if (!url) return;

  const topLevDomain = getTopLevelDomain();
  const allDomain = getTopLevelDomain('all');
  let baseUrl = '';
  if (topLevDomain === allDomain) {
    baseUrl = `https://game.${topLevDomain}`;
  } else {
    baseUrl = `https://game-${allDomain}`;
  }

  const gameUrl = `${baseUrl}${url}?${toQuery(getQuery().query)}`;
  window.location.href = gameUrl;
  window._BeylaCls?.gameClickReport(game);
};

const afc = ref(null);
const afc2 = ref(null);
const afc3 = ref(null);

const showAdsPopup = ref(false);

const _loadAFC = (domId, ref, slotId) => {
  const ls = Array.isArray(ref) ? ref : [ref];
  ls.forEach((dom) => {
    if (!dom) return;
    if (cur.platform === 'GAM') {
      const boxId = `div-gpt-ad-${slotId}-0`;
      const div = document.createElement('div');
      div.id = boxId;
      const randomLs = Array.from({ length: 16 }, () =>
        Math.floor(Math.random() * 16).toString(16),
      ).join('');
      const nonceText = `nonce-${randomLs}`;
      const script = document.createElement('script');
      script.textContent = `googletag.cmd.push(function() { googletag.display('${boxId}') })`;
      script.setAttribute('nonce', nonceText);
      div.appendChild(script);
      dom.appendChild(div);
    } else {
      const load_ad_params = `<ins class="adsbygoogle" style="display:block;width:100%;height:50px" data-ad-client="ca-pub-${cur.ca_pub}" data-ad-slot="${slotId}" data-ad-format="auto" data-full-width-responsive="true" data-ad-ref="${domId}"></ins>`;
      dom.innerHTML = load_ad_params;
      window.adsbygoogle.push({});
    }
  });
};
const _loadAFG = () => {
  const ca_pub_id = `ca-pub-${cur.ca_pub}`;
  const adsScript = document.createElement('script');
  adsScript.src = `//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${ca_pub_id}`;
  adsScript.async = true;
  adsScript.crossOrigin = 'anonymous';
  adsScript.setAttribute('data-ad-client', ca_pub_id);
  adsScript.setAttribute('data-ad-frequency-hint', '30s');
  adsScript.onload = function () {
    window.adsbygoogle = window.adsbygoogle || [];
    window.adsbygoogle.push({
      preloadAdBreaks: 'on',
      sound: 'off',
    });

    window.adsbygoogle.push({
      type: 'preroll',
      name: 'app_start',
      adBreakDone: () => {},
    });
  };
  document.head.appendChild(adsScript);
};

const handleFooterClick = (type) => {
  if (type.includes('@')) return;
  window.location.href = `/${type.toLowerCase()}/index.html`;
};

const autoPopup = () => {
  if (!cur.p_slot) return;

  const timer = window.setTimeout(() => {
    if (showAdsPopup.value) {
      window.clearTimeout(timer);
      return;
    }
    showAdsPopup.value = true;
  }, 6000);
};

let fromAutoClose = false;
const handelPopupOpened = () => {
  _loadAFC('afc3', afc3.value, cur.p_slot);

  setTimeout(() => {
    const targetNode = afc3.value?.firstElementChild;
    const observer = new MutationObserver((mutationsList) => {
      for (var mutation of mutationsList) {
        if (mutation.type === 'attributes') {
          if (targetNode.getAttribute(mutation.attributeName) === 'unfilled') {
            fromAutoClose = true;
            showAdsPopup.value = false;
          }
        }
      }
    });
    observer.observe(targetNode, {
      attributes: true,
      attributeFilter: ['data-ad-status'],
    });
    setTimeout(() => {
      observer.disconnect();
    }, 3000);
  });
};
const handelPopupClose = () => {
  if (fromAutoClose) {
    fromAutoClose = false;
  }
};

onMounted(() => {
  // 添加窗口大小变化监听
  window.addEventListener('resize', handleResize);

  window._adsLoaded().then(() => {
    cur = formatConfig(get(window, 'curPortalConfig', {}));
    const { s, s2, p_slot, safg_pre } = cur;

    if (s) _loadAFC('afc', afc.value, s);
    if (s2) _loadAFC('afc2', afc2.value, s2);
    if (safg_pre) _loadAFG();
    if (getUrlParam('ap') !== '0' && p_slot) autoPopup();
  });
});

// 获取推荐游戏用于banner
const recommendGames = ref(gameData.Recommend || []);

// 将推荐游戏分组用于轮播（每页3个游戏）
const gamesPerSlide = 3;

const recommendGamesSlides = computed(() => {
  const slides = [];
  const games = recommendGames.value;

  // 每页3个游戏
  for (let i = 0; i < games.length; i += gamesPerSlide) {
    slides.push(games.slice(i, i + gamesPerSlide));
  }

  return slides;
});

// 轮播图相关状态
const swipeRef = ref(null);
const autoplayEnabled = ref(true);
const currentIndex = ref(0);

// 切换到上一张
const prevSlide = () => {
  if (swipeRef.value) {
    swipeRef.value.prev();
  }
};

// 切换到下一张
const nextSlide = () => {
  if (swipeRef.value) {
    swipeRef.value.next();
  }
};

// 鼠标悬停时暂停自动播放
const handleMouseEnter = () => {
  autoplayEnabled.value = false;
};

// 鼠标离开时恢复自动播放
const handleMouseLeave = () => {
  autoplayEnabled.value = true;
};

// 轮播切换事件
const handleChange = (index) => {
  currentIndex.value = index;
};

// 获取全部游戏（过滤隐藏的游戏）
const allGames = ref(
  gameList
    .filter((game) => !game.hidden && game.name && game.name !== 'Home')
    .map((item, idx) => ({ ...item, idx })),
);

// 移动端初始显示6行（5列布局，共30个游戏）
// PC端初始显示6行（9列布局，共54个游戏）
const initialRows = 6;
const loadMoreRows = 3;
const gamesPerRowMobile = 5; // 移动端5列
const gamesPerRowPC = 9; // PC端9列

// 检测是否为PC端（宽度 >= 1025px）
const isPC = ref(window.innerWidth >= 1025);

// 监听窗口大小变化
const handleResize = () => {
  isPC.value = window.innerWidth >= 1025;
};

// 根据设备类型计算初始显示数量
const initialCount = computed(() => {
  const gamesPerRow = isPC.value ? gamesPerRowPC : gamesPerRowMobile;
  return initialRows * gamesPerRow;
});

// 根据设备类型计算每次加载更多数量
const loadMoreCount = computed(() => {
  const gamesPerRow = isPC.value ? gamesPerRowPC : gamesPerRowMobile;
  return loadMoreRows * gamesPerRow;
});

const displayedCount = ref(initialCount.value);
// 记录上一次的初始数量，用于判断是否需要更新
const prevInitialCount = ref(initialCount.value);

// 监听窗口大小变化，更新显示数量
watch(initialCount, (newCount) => {
  // 如果当前显示数量等于上一次的初始数量，说明用户还没有加载更多，更新为新的初始数量
  // 如果已经加载了更多，则保持当前数量
  if (displayedCount.value === prevInitialCount.value) {
    displayedCount.value = newCount;
  }
  prevInitialCount.value = newCount;
});

onBeforeUnmount(() => {
  window.removeEventListener('resize', handleResize);
});

// 当前显示的游戏列表
const displayedGames = computed(() => {
  return allGames.value.slice(0, displayedCount.value);
});

// 是否还有更多游戏
const hasMore = computed(() => {
  return displayedCount.value < allGames.value.length;
});

// 加载更多游戏
const loadMore = () => {
  displayedCount.value += loadMoreCount.value;
};
</script>

<template>
  <div class="game-center-wrap">
    <!-- 顶部分类导航 -->
    <div class="category-nav">
      <!-- 顶部第一行：Logo和操作按钮 -->
      <div class="nav-top-row">
        <!-- Logo区域 -->
        <div class="nav-logo" @click="handleLogoClick">
          <img src="@/assets/img/logo.png" alt="Puzzle Games Pro" />
          <span>Puzzle Games Pro</span>
        </div>

        <!-- 操作按钮容器 -->
        <div class="nav-actions">
          <!-- 首页图标 -->
          <div class="nav-home" @click="handleLogoClick" title="front page">
            <svg
              width="18"
              height="18"
              viewBox="0 0 24 24"
              fill="none"
              xmlns="http://www.w3.org/2000/svg"
            >
              <path
                d="M3 12L5 10M5 10L12 3L19 10M5 10V20C5 20.5523 5.44772 21 6 21H9M19 10L21 12M19 10V20C19 20.5523 18.5523 21 18 21H15M9 21C9.55228 21 10 20.5523 10 20V16C10 15.4477 10.4477 15 11 15H13C13.5523 15 14 15.4477 14 16V20C14 20.5523 14.4477 21 15 21M9 21H15"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
              />
            </svg>
          </div>

          <!-- 搜索图标 -->
          <div class="nav-search" @click="handleSearchClick" title="search">
            <img src="@/assets/img/search.svg" alt="Search" />
          </div>
        </div>
      </div>

      <!-- 第二行：分类导航容器 -->
      <div class="category-nav-container" ref="categoryNavContainer">
        <div
          class="category-nav-item"
          :class="{ active: category === currentCategory }"
          v-for="category in categoryList"
          :key="category"
          @click="handleCategoryClick(category)"
        >
          <span>{{ category }}</span>
        </div>
      </div>
    </div>

    <div class="game-content">
      <div class="advertising top" ref="afc"></div>

      <!-- 推荐游戏Banner -->
      <div class="recommend-banner" v-if="recommendGames.length > 0">
        <div class="banner-title">recommend</div>

        <!-- 推荐游戏轮播 -->
        <div class="banner-swipe" @mouseenter="handleMouseEnter" @mouseleave="handleMouseLeave">
          <!-- 左箭头 -->
          <div
            class="banner-nav-arrow banner-nav-arrow-left"
            @click="prevSlide"
            v-if="recommendGamesSlides.length > 1"
          >
            <svg
              width="20"
              height="20"
              viewBox="0 0 24 24"
              fill="none"
              xmlns="http://www.w3.org/2000/svg"
            >
              <path
                d="M15 18L9 12L15 6"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
              />
            </svg>
          </div>

          <!-- 右箭头 -->
          <div
            class="banner-nav-arrow banner-nav-arrow-right"
            @click="nextSlide"
            v-if="recommendGamesSlides.length > 1"
          >
            <svg
              width="20"
              height="20"
              viewBox="0 0 24 24"
              fill="none"
              xmlns="http://www.w3.org/2000/svg"
            >
              <path
                d="M9 18L15 12L9 6"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
              />
            </svg>
          </div>

          <van-swipe
            ref="swipeRef"
            :autoplay="autoplayEnabled ? 3000 : 0"
            :loop="true"
            :show-indicators="true"
            indicator-color="rgba(255, 255, 255, 0.4)"
            indicator-size="8px"
            :duration="600"
            :touchable="true"
            @change="handleChange"
          >
            <van-swipe-item v-for="(slide, slideIndex) in recommendGamesSlides" :key="slideIndex">
              <div class="banner-games">
                <div
                  v-for="game in slide"
                  :key="game.key"
                  class="banner-game-item"
                  @click="handleBannerGameClick(game)"
                >
                  <div class="banner-game-icon-wrapper">
                    <GameItem :game="game" class="banner-game-icon" />
                  </div>
                  <div class="banner-game-name">{{ game.name }}</div>
                </div>
              </div>
            </van-swipe-item>
          </van-swipe>
        </div>
      </div>

      <div class="game-list">
        <div class="advertising" ref="afc2"></div>
        <div
          v-for="game in displayedGames"
          :key="game.name || game.key"
          :class="[
            'game-item-wrapper',
            {
              hide: !game.name || game.hidden,
            },
          ]"
        >
          <GameItem :game="game" class="game-item" />
          <div class="game-name">{{ game.name }}</div>
        </div>
      </div>

      <!-- 加载更多按钮 -->
      <div class="load-more-container" v-if="hasMore">
        <button class="load-more-btn" @click="loadMore">Load more</button>
      </div>
    </div>

    <div class="footer">
      <div
        class="link-item"
        v-for="type in ['Privacy', 'TOS', 'Contact', '@' + getTopLevelDomain()]"
        :key="type"
        @click="handleFooterClick(type)"
      >
        {{ type }}
      </div>
    </div>

    <van-popup
      v-model:show="showAdsPopup"
      position="center"
      :close-on-click-overlay="false"
      closeable
      :lazy-render="false"
      class="ads-popup"
      @opened="handelPopupOpened"
      @close="handelPopupClose"
    >
      <div class="ads-popup--warp" ref="afc3"></div>
    </van-popup>
  </div>
</template>

<style lang="scss" scoped>
.game-center-wrap {
  position: relative;
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  color: #fff;

  // 顶部分类导航
  .category-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: auto;

    // 顶部第一行：Logo和操作按钮
    .nav-top-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 12px;
      gap: 12px;
      min-height: 48px;
    }

    // Logo区域
    .nav-logo {
      flex: 1;
      display: flex;
      align-items: center;
      gap: 6px;
      cursor: pointer;
      transition: opacity 0.2s ease;
      min-width: 0;

      &:active {
        opacity: 0.7;
      }

      img {
        height: 20px;
        width: auto;
        flex-shrink: 0;
      }

      span {
        font-size: 12px;
        color: #fff;
        font-weight: 600;
        -webkit-text-fill-color: transparent;
        -webkit-background-clip: text;
        background-clip: text;
        background-image: linear-gradient(45deg, #4398d1, #fdb62f, #c94536, #88b337);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }

    // 操作按钮容器（首页和搜索）
    .nav-actions {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-shrink: 0;
    }

    // 首页图标
    .nav-home {
      flex-shrink: 0;
      width: 36px;
      height: 36px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: all 0.2s ease;
      color: #fff;
      border-radius: 8px;
      background: rgba(255, 255, 255, 0.1);

      &:active {
        transform: scale(0.95);
        background: rgba(255, 255, 255, 0.2);
      }

      svg {
        width: 18px;
        height: 18px;
      }
    }

    // 搜索图标
    .nav-search {
      flex-shrink: 0;
      width: 36px;
      height: 36px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: all 0.2s ease;
      border-radius: 8px;
      background: rgba(255, 255, 255, 0.1);

      &:active {
        transform: scale(0.95);
        background: rgba(255, 255, 255, 0.2);
      }

      img {
        width: 18px;
        height: 18px;
      }
    }

    // 分类导航容器（第二行）
    .category-nav-container {
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 8px 12px;
      overflow-x: auto;
      overflow-y: hidden;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: none;
      -ms-overflow-style: none;

      &::-webkit-scrollbar {
        display: none;
      }

      .category-nav-item {
        flex-shrink: 0;
        padding: 6px 12px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.3s ease;
        white-space: nowrap;
        backdrop-filter: blur(10px);
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        min-height: 28px;
        position: relative;

        &:active {
          transform: scale(0.95);
        }

        // 激活状态样式
        &.active {
          background: rgba(255, 255, 255, 0.35);
          box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);

          span {
            font-weight: 600;
            color: #fff;
          }

          // 添加底部指示线
          &::after {
            content: '';
            position: absolute;
            bottom: 2px;
            left: 50%;
            transform: translateX(-50%);
            width: 60%;
            height: 2px;
            background: rgba(255, 255, 255, 0.9);
            border-radius: 1px;
          }
        }

        span {
          font-size: 11px;
          color: rgba(255, 255, 255, 0.9);
          font-weight: 500;
          text-align: center;
          transition: all 0.3s ease;
        }
      }
    }
  }

  .game-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 0 20px 0;
    min-height: 100vh;
    overflow-x: hidden;
    box-sizing: border-box;

    // 推荐游戏Banner
    .recommend-banner {
      margin: 16px 0;
      padding: 0 12px;

      .banner-title {
        font-size: 14px;
        font-weight: 600;
        color: #fff;
        margin-bottom: 10px;
        text-align: center;
      }

      // 推荐游戏轮播
      .banner-swipe {
        position: relative;
        padding: 0 8px;

        .banner-games {
          display: grid;
          grid-template-columns: repeat(3, 1fr);
          gap: 8px;
          padding: 8px 0;

          .banner-game-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            cursor: pointer;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            padding: 4px;
            border-radius: 10px;

            &:hover {
              transform: translateY(-4px) scale(1.05);

              .banner-game-icon-wrapper {
                box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
              }

              .banner-game-name {
                color: #fff;
                opacity: 1;
              }
            }

            &:active {
              transform: translateY(-2px) scale(1.02);
            }

            .banner-game-icon-wrapper {
              width: 100%;
              aspect-ratio: 1;
              border-radius: 12px;
              overflow: hidden;
              max-width: 50px;
              transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
              box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
              background: rgba(255, 255, 255, 0.1);
              backdrop-filter: blur(10px);

              .banner-game-icon {
                width: 100%;
                height: 100%;
              }
            }

            .banner-game-name {
              margin-top: 6px;
              font-size: 10px;
              color: rgba(255, 255, 255, 0.9);
              text-align: center;
              line-height: 1.3;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              line-clamp: 2;
              -webkit-box-orient: vertical;
              word-break: break-word;
              transition: all 0.3s ease;
              font-weight: 500;
            }
          }
        }

        // 导航箭头
        .banner-nav-arrow {
          position: absolute;
          top: 50%;
          transform: translateY(-50%);
          z-index: 10;
          width: 36px;
          height: 36px;
          display: none; // 移动端默认隐藏
          align-items: center;
          justify-content: center;
          background: rgba(255, 255, 255, 0.15);
          backdrop-filter: blur(10px);
          border-radius: 50%;
          cursor: pointer;
          transition: all 0.3s ease;
          color: #fff;
          opacity: 0;
          pointer-events: none;

          &:hover {
            background: rgba(255, 255, 255, 0.25);
            transform: translateY(-50%) scale(1.1);
          }

          &:active {
            transform: translateY(-50%) scale(0.95);
          }

          svg {
            width: 20px;
            height: 20px;
          }
        }

        .banner-nav-arrow-left {
          left: 0;
        }

        .banner-nav-arrow-right {
          right: 0;
        }

        // 鼠标悬停时显示箭头（仅PC端）
        &:hover .banner-nav-arrow {
          opacity: 1;
          pointer-events: auto;
        }

        // 轮播指示器样式
        :deep(.van-swipe__indicators) {
          bottom: -16px;
          gap: 5px;
        }

        :deep(.van-swipe__indicator) {
          width: 8px;
          height: 8px;
          border-radius: 50%;
          background: rgba(255, 255, 255, 0.4);
          transition: all 0.3s ease;
          opacity: 0.6;
        }

        :deep(.van-swipe__indicator--active) {
          width: 20px;
          border-radius: 4px;
          background: rgba(255, 255, 255, 0.9);
          opacity: 1;
        }

        // 轮播容器样式
        :deep(.van-swipe) {
          overflow: visible;
        }

        :deep(.van-swipe-item) {
          overflow: visible;
        }
      }
    }

    .game-list {
      display: grid;
      grid-template-columns: repeat(5, 1fr);
      gap: 8px;
      padding: 0 12px;
      margin: 10px 0;
      box-sizing: border-box;

      .advertising {
        grid-column: 1 / -1;
        margin: 10px -12px;
      }

      .game-item-wrapper {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        box-sizing: border-box;

        &.hide {
          display: none;
        }

        .game-item {
          position: relative;
          display: flex;
          justify-content: center;
          align-items: center;
          aspect-ratio: 1;
          overflow: hidden;
          width: 100%;
          max-width: 50px;
          box-sizing: border-box;
        }

        .game-name {
          margin-top: 4px;
          font-size: 10px;
          color: #fff;
          text-align: center;
          line-height: 1.2;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          line-clamp: 2;
          -webkit-box-orient: vertical;
          word-break: break-word;
          width: 100%;
          max-width: 60px;
        }
      }
    }

    // 加载更多按钮
    .load-more-container {
      display: flex;
      justify-content: center;
      margin: 20px 0;
      padding: 0 16px;

      .load-more-btn {
        padding: 6px 18px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: #fff;
        border: none;
        border-radius: 16px;
        font-size: 11px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);

        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        }

        &:active {
          transform: translateY(0);
        }
      }
    }

    .advertising {
      width: 100%;
    }
  }

  // PC端适配 (1025px及以上，iPad使用移动端布局)
  @media (min-width: 1025px) {
    .game-content {
      .recommend-banner {
        .banner-swipe {
          padding: 0 30px;

          // PC端显示导航箭头
          .banner-nav-arrow {
            display: flex;
          }
        }
      }
    }

    .category-nav {
      flex-direction: row;
      padding: 5px 10px;
      min-height: 40px;
      align-items: center;
      gap: 6px;
      overflow: hidden;

      .nav-top-row {
        flex-shrink: 0;
        padding: 0;
        min-height: auto;
        gap: 4px;
        display: flex;
        align-items: center;
      }

      .nav-logo {
        gap: 2px;
        flex-shrink: 0;
        max-width: 100px;

        img {
          height: 10px;
        }

        span {
          font-size: 9px;
        }
      }

      .nav-actions {
        gap: 4px;
        flex-shrink: 0;
      }

      .nav-home {
        width: 24px;
        height: 24px;
        flex-shrink: 0;

        svg {
          width: 12px;
          height: 12px;
        }
      }

      .category-nav-container {
        flex: 1;
        min-width: 0;
        padding: 0;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
        justify-content: flex-start;
        gap: 2px;

        &::-webkit-scrollbar {
          height: 4px;
        }

        &::-webkit-scrollbar-track {
          background: transparent;
        }

        &::-webkit-scrollbar-thumb {
          background: rgba(255, 255, 255, 0.3);
          border-radius: 2px;

          &:hover {
            background: rgba(255, 255, 255, 0.5);
          }
        }

        .category-nav-item {
          padding: 2px 6px;
          min-height: 22px;
          flex-shrink: 0;
          position: relative;

          &.active {
            background: rgba(255, 255, 255, 0.35);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);

            span {
              font-weight: 600;
            }

            &::after {
              content: '';
              position: absolute;
              bottom: 1px;
              left: 50%;
              transform: translateX(-50%);
              width: 60%;
              height: 1.5px;
              background: rgba(255, 255, 255, 0.9);
              border-radius: 1px;
            }
          }

          span {
            font-size: 8px;
          }
        }
      }

      .nav-search {
        width: 24px;
        height: 24px;
        flex-shrink: 0;

        img {
          width: 12px;
          height: 12px;
        }
      }
    }

    .game-content {
      max-width: 1600px;
      margin: 0 auto;
      padding: 0 50px;
      box-sizing: border-box;

      .recommend-banner {
        padding: 0 50px;
        margin: 20px 0;

        .banner-title {
          font-size: 16px;
          margin-bottom: 12px;
        }

        .banner-swipe {
          padding: 0 40px;

          .banner-games {
            grid-template-columns: repeat(3, 1fr);
            gap: 15px;
            padding: 10px 0;

            .banner-game-item {
              padding: 8px;

              .banner-game-icon-wrapper {
                max-width: 60px;
                border-radius: 12px;
                box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
              }

              .banner-game-name {
                font-size: 10px;
                margin-top: 6px;
              }
            }
          }

          .banner-nav-arrow {
            width: 44px;
            height: 44px;
            opacity: 0.7;

            svg {
              width: 24px;
              height: 24px;
            }
          }

          // 轮播指示器样式
          :deep(.van-swipe__indicators) {
            bottom: -20px;
            gap: 6px;
          }

          :deep(.van-swipe__indicator) {
            width: 10px;
            height: 10px;
          }

          :deep(.van-swipe__indicator--active) {
            width: 24px;
          }
        }
      }

      .game-list {
        grid-template-columns: repeat(9, 1fr);
        gap: 5px;
        padding: 0 50px;

        .advertising {
          margin: 10px -50px;
        }

        .game-item-wrapper {
          .game-item {
            max-width: 40px;
          }

          .game-name {
            font-size: 5px;
            margin-top: 2px;
            max-width: 50px;
          }
        }
      }

      .load-more-container {
        padding: 0 50px;

        .load-more-btn {
          padding: 7px 24px;
          font-size: 11px;
        }
      }
    }
  }

  // 大屏PC端适配
  @media (min-width: 1024px) {
    .game-content {
      padding: 0 50px;

      .game-list {
        grid-template-columns: repeat(9, 1fr);
        gap: 6px;
        padding: 0 60px;

        .advertising {
          margin: 10px -60px;
        }

        .game-item-wrapper {
          .game-item {
            max-width: 50px;
          }

          .game-name {
            font-size: 6px;
            margin-top: 3px;
            max-width: 60px;
          }
        }
      }
    }
  }

  // 超大屏PC端适配
  @media (min-width: 1440px) {
    .game-content {
      padding: 0 60px;

      .game-list {
        grid-template-columns: repeat(9, 1fr);
        gap: 8px;
        padding: 0 70px;

        .advertising {
          margin: 10px -70px;
        }

        .game-item-wrapper {
          .game-item {
            max-width: 60px;
          }

          .game-name {
            font-size: 8px;
            margin-top: 4px;
            max-width: 70px;
          }
        }
      }
    }
  }

  .footer {
    font-size: 14px;
    line-height: 30px;
    padding: 24px 0;
    text-align: center;
    background: #fff;
    color: #555;

    & > div {
      display: inline-block;
      padding: 0 10px;
      position: relative;

      &:not(&:last-child) {
        text-decoration: underline;

        &::after {
          content: '';
          display: block;
          position: absolute;
          top: 9px;
          right: 0;
          width: 1px;
          height: 14px;
          background: #555;
        }
      }
    }
  }

  .ads-popup {
    width: calc(100% - 2px);
    padding: 30px 0px 1px;
    border-radius: 10px;
    overflow: hidden;
    max-height: calc(100vh - 35px);

    &--warp {
      min-height: 312px;
    }
  }
}
</style>
<style lang="scss">
.game-center-wrap {
  .ads-popup {
    max-width: unset;

    .van-icon {
      padding: 8px;
      transform: translate(18px, -20px) scale(0.8);
    }
  }
}

.loading-dialog {
  background: none;

  .van-loading {
    overflow: hidden;
  }
}

.autoSizeSearch.van-search > div {
  padding-left: 20px;
  height: 100%;
  line-height: 100%;

  & > div {
    height: 100%;
  }
}
</style>
